using System.Xml;
using Coffee.DataModels;

namespace Coffee.DataMappers
{
    public class DummyProxyMapper : IDataMapper
    {
        DataProxy current;
        DataProxy previous;

        public DummyProxyMapper()
            : base()
        {
            Initialize();
        }

        public DataModel Current { get { return current; } }
        public DataModel Previous { get { return previous; } }

        public DummyProxyMapper(XmlNode configuration)
        {
            this.configuration = configuration;
            Initialize();
        }


        protected XmlNode configuration;

        protected virtual void Initialize()
        {
            current = new DataProxy();
            previous = new DataProxy();

            XmlNodeList questions = configuration.SelectNodes("configuration/question");
            foreach (XmlNode question in questions)
            {
                string id = question.Attributes["id"].Value;
                current.AddProperty(id);
                previous.AddProperty(id);

                if (question.SelectSingleNode("binding") != null)
                {
                    string cbind = question.SelectSingleNode("binding/current/text()").Value;
                    string pbind = question.SelectSingleNode("binding/previous/text()").Value;

                    if (!current.PropertyExists(cbind))
                        current.AddProperty(cbind);
                    if (!previous.PropertyExists(pbind))
                        previous.AddProperty(pbind);
                }

            }

        }

        public void Load()
        {
            //DataSet ds = DataSources.ExecuteFetch("Coffee_Fetch_" + configuration.ParentNode.Attributes["id"].Value, sqlParamList.Items);

            //DataRow curr = null;
            //DataRow prev = null;

            //if (ds.Tables[0].Rows.Count == 1) curr = ds.Tables[0].Rows[0];
            //if (ds.Tables[1].Rows.Count == 1) prev = ds.Tables[1].Rows[0];

            string[] currkeys = new string[current.Properties.Count];
            string[] prevkeys = new string[previous.Properties.Count];

            current.Properties.Keys.CopyTo(currkeys, 0);
            previous.Properties.Keys.CopyTo(prevkeys, 0);

            foreach (string property in currkeys)
            {
                current.SetProperty(property, "Dummy");
            }

            foreach (string property in prevkeys)
            {
                previous.SetProperty(property, "Dummy");
            }

        }

        public void Update()
        {
            string[] currkeys = new string[current.Properties.Count];
            current.Properties.Keys.CopyTo(currkeys, 0);

            foreach (string property in currkeys)
            {
                //sqlParamList.Add(property, current.GetProperty(property));
            }

        }
    }

}